<template>
	<view class="poster-content">
		<yk-header :title="title" @headBtn="headBtn()" @closePage="closePage()"></yk-header>
		<image :src="imgUrl" mode="widthFix"></image>
		<view v-if="version == 1">
		</view>
		<view class="btn-box" v-else>
			<view @click="save">保存至相册</view>
			<view @click="share">分享</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '海报',
				imgUrl: 'g',
				version: 0,
			}
		},
		onLoad(event) {
			console.log(event.url);
			this.imgUrl = event.url;
			console.log(this.imgUrl);
			this.version = window.version;
		},
		onShow() {
			window.genVersion();
			this.imgUrl = this.imgUrl;
			console.log(this.imgUrl);
		},
		methods: {
			//顶部功能键
			headBtn(e) {
				let that = this;
				uni.showActionSheet({
					itemList: ['刷新', '清除缓存'],
					success: function(res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if (res.tapIndex == 0) {
							//刷新
							uni.showLoading({
								title: '刷新中'
							});
							setTimeout(function() {
								uni.hideLoading();
							}, 1500);

						} else {
							//清楚缓存
							// callNative('onClearH5Cache')
							uni.showToast({
								title: '清除缓存成功'
							});
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			//关闭当前页面
			closePage() {
				callNative('navigateBack')
			},
			save() {
				console.log('save img url===' + this.imgUrl);
				onSavePhoto(this.imgUrl);
			},
			share() {
				console.log('share img url===' + this.imgUrl);
				onShare('', '', this.imgUrl, '');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.poster-content {
		width: 100%;
		min-width: 750px;
		font-size: 36px;

		image {
			width: 100%;
			display: block;
		}

		.btn-box {
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 100px;
			overflow: auto;
			text-align: center;

			view {
				float: left;
				line-height: 100px;
				width: 50%;
				color: #fff;
			}

			view:nth-child(1) {
				background: #4DB6FF;
			}

			view:nth-child(2) {
				background: #0096FF;
			}
		}
	}
</style>
